{include file="public/layout" /}
<body class="laytp-container">
<div class="layui-card" id="search-form">
    <div class="layui-card-body">
        <form class="layui-form" action="">
    <input type="hidden" name="info[id]" value="{$info.id|default=0}" />

    <div class="layui-form-item">
        <label class="layui-form-label">财务类型</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" name="info[action]" value="{$info.action|default=''}" placeholder="请输入" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">规则标题</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" name="info[name]" placeholder="请输入" value="{$info.name}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">支付顺序</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" name="info[px]" placeholder="请输入" value="{$info.px|default=0}" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid">越大越靠前</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">支付表名</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" name="info[biaoming]" placeholder="请输入" value="{$info.biaoming|default=''}" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">匹配条件</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" name="info[tiaojian]" placeholder="请输入" value="{$info.tiaojian|default=''}" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid">例：普通商品[leixing_id]=1，全部匹配请设置为 1=1</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">价格表达式</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" name="info[ziduan]" placeholder="请输入" value="{$info.ziduan|default=''}" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid">例：支付金额+运费 [total_shop_price]+[shipping_price]</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">是否抵扣</label>
        <div class="layui-input-block">
            <input type="radio" name="info[dikou]" value="0" title="否" {if !$info || !$info['dikou']}checked{/if} />
            <input type="radio" name="info[dikou]" value="1" title="是" {if $info && $info['dikou']==1}checked{/if} >
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">抵扣规则ID</label>
        <div class="layui-input-inline layui-input-wrap">
            <input type="text" name="info[dikou_id]" placeholder="请输入" value="{$info.dikou_id|default=''}" autocomplete="off" class="layui-input">
        </div>
        <div class="layui-form-mid">优先计算抵扣规则，然后再从关联规则中扣除相应金额</div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">钱包配置</label>
        <div class="layui-input-inline layui-input-wrap" style="width: 500px;">
            <table class="layui-table">
                <tr>
                    <th width="100">钱包名称1</th>
                    <th width="200">支付顺序(越小越靠前)</th>
                </tr>
                <?php $i=1; ?>
                {foreach $wallet as $key=>$name}
                    <tr>
                        <td><input type="checkbox" name="wallet[]" value="{$key}" {if isset($info['wallet']) && $info['wallet']!='' && in_array($key,array_keys($info['wallet']))}checked="checked"{/if} title="{$name}" /></td>
                        <td><input class="layui-input" type="text" value="{$info['wallet'][$key]|default=$i}" name="walletpx[]" size="6"/></td>
                        <?php $i++; ?>
                    </tr>
                {/foreach}
            </table>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">在线支付</label>
        <div class="layui-input-block">
            <input type="radio" name="onlinepay" value="0" title="关闭" {if !$info || !$info['onlinepay']}checked{/if} />
            <input type="radio" name="onlinepay" value="1" title="启用" {if $info && $info['onlinepay']==1}checked{/if} >
        </div>
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="submit" class="layui-btn" lay-submit lay-filter="demo1">确认</button>
        </div>
    </div>
</form>
    </div>
</div>
<!-- 请勿在项目正式环境中引用该 layui.js 地址 -->
<script>
    layui.use(['form', 'laydate', 'util'], function(){
        var form = layui.form;
        var layer = layui.layer;
        var laydate = layui.laydate;
        var util = layui.util;

        // 提交事件
        form.on('submit(demo1)', function(data){
            var index = layer.load();
            layer.close(index);

            var field = data.field; // 获取表单字段值
            $.ajax({
                type: "POST",
                url: "{:url('save')}",
                data: field,
                success: function(res){
                    console.log(res);
                    if(res.status){
                        layer.msg('提交成功');
                    }else{
                        layer.msg(res.msg);
                    }
                    setTimeout(function(){
                        parent.layer.closeAll();
                        parent.tableIns.reload()
                    },1000)
                }
            });
            return false; // 阻止默认 form 跳转
        });

        // 日期
        laydate.render({
            elem: '#date'
        });


    });
</script>
</body>
</html>